package com.ian.controller;

import com.common.util.ResultMsg;
import com.ian.pojo.PerCard;
import com.ian.service.PerCardService;
import com.ian.service.PerUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 上传身份证
 */
@Api("身份证相关API")
@RestController
public class PerCardController {
    @Autowired
    PerUserService perUserService;

    @Autowired
    PerCardService perCardService;

    @ApiOperation("上传身份证正面照片")
    @PutMapping(value = "/uploadCardA", produces = "application/json;charset=UTF-8")
    public ResultMsg uploadCardA(@RequestParam("mobile") String mobile, @RequestParam("path") String path) {
        PerCard perCard = perCardService.findByUid(perUserService.findByTel(mobile).getPerUserId());
        perCard.setPerCardId(perCard.getPerCardId());
        perCard.setPerCardImg2(perCard.getPerCardImg2());
        perCard.setPerUserId(perCard.getPerUserId());
        perCard.setPerCardImg1(path);
        perCardService.updateByPrimaryKeySelective(perCard);
        return ResultMsg.success("上传身份证正面成功~", path);
    }

    @ApiOperation("上传身份证反面照片")
    @PutMapping(value = "/uploadCardB", produces = "application/json;charset=UTF-8")
    public ResultMsg uploadCardB(@RequestParam("mobile") String mobile, @RequestParam("path") String path) {
        PerCard perCard = perCardService.findByUid(perUserService.findByTel(mobile).getPerUserId());
        perCard.setPerCardImg2(path);
        perCard.setPerCardId(perCard.getPerCardId());
        perCard.setPerUserId(perCard.getPerUserId());
        perCard.setPerCardImg1(perCard.getPerCardImg1());
        perCardService.updateByPrimaryKeySelective(perCard);
        return ResultMsg.success("上传身份证反面成功~", path);
    }

    @ApiOperation("查询用户身份证信息")
    @GetMapping(value = "/userCard", produces = "application/json;charset=UTF-8")
    public ResultMsg userCard(@RequestParam("mobile") String mobile) {
        PerCard card = perCardService.findByUid(perUserService.findByTel(mobile).getPerUserId());
        return ResultMsg.success("查询身份证信息成功~", card);
    }
}
